#!/bin/bash

echo "==================================="
echo "    IoT数据处理系统启动脚本"
echo "==================================="
echo

# 检查Java环境
echo "检查Java环境..."
if ! command -v java &> /dev/null; then
    echo "错误: 未找到Java环境，请安装Java 11或更高版本"
    exit 1
fi
java -version

echo
# 检查Maven环境
echo "检查Maven环境..."
if ! command -v mvn &> /dev/null; then
    echo "错误: 未找到Maven环境，请安装Maven 3.6或更高版本"
    exit 1
fi
mvn -version

echo
# 编译项目
echo "编译项目..."
mvn clean compile
if [ $? -ne 0 ]; then
    echo "错误: 项目编译失败"
    exit 1
fi

echo
# 运行测试
echo "运行测试..."
mvn test
if [ $? -ne 0 ]; then
    echo "警告: 测试执行失败，但继续启动应用程序"
fi

echo
echo "启动应用程序..."
echo "注意: 请确保Redis服务已启动 (默认 localhost:6379)"
echo

# 启动应用程序
mvn exec:java -Dexec.mainClass="com.iot.processor.Application"